package lei.k_java字符串处理;

import com.alibaba.fastjson.JSONObject;

import java.util.Arrays;
import java.util.List;

/**
 * @className: StringExample
 * @author: xl
 * @date: 2025/3/3 20:27
 * @Version: 1.0
 * @description:
 */

public class StringExample {

    public static void main(String[] args) {

        String str="hello world ";

        int a=str.length();
        System.out.println(a);

        // 截取字符串
        String str1=str.substring(0,5);
        System.out.println(str1);

        // 替换字符串
        String str2=str.replace("h","H");
        System.out.println(str2);

        // 分割字符串
        String[] str3=str.split(" ");
        System.out.println(Arrays.toString(str3));

        // 去除空格
        String str4=str.trim();
        System.out.println(str4);

        // 大小写转换
        String str5=str.toUpperCase();
        System.out.println(str5);

        int str6=str.indexOf("w");
        int str7=str.indexOf("d");
        System.out.println(str.substring(str6,str7+1));

        Boolean str8=str.equals("hello");
        System.out.println(str8);

        String name = "Alice";
        int age = 25;

        // 使用 String.format()
        String formatted1 = String.format("Name: %s, Age: %d", name, age);
        System.out.println(formatted1);

        System.out.printf("Name: %s, Age: %d\n", name, age); // 输出: Name: Alice, Age: 25
        System.out.printf("Name: %s, Age: %d\n", name, age); // 输出: Name: Alice, Age: 25



        String schools="{\"schoolInfo\":{\"schoolId\":\"SCH-2025-001\",\"schoolName\":\"阳光实验学校\",\"establishYear\":1995,\"address\":{\"province\":\"江苏省\",\"city\":\"南京市\",\"district\":\"鼓楼区\",\"detail\":\"中山北路 123 号\"},\"contact\":{\"phone\":\"025-87654321\",\"email\":\"yangguang@school.edu.cn\",\"website\":\"http://www.yangguangschool.com\"},\"type\":\"九年一贯制\",\"studentCount\":2850,\"teacherCount\":198,\"feature\":[\"科技创新教育\",\"艺术特色\",\"体育传统项目学校\"]},\"departments\":[{\"departmentId\":\"DEP-001\",\"departmentName\":\"教务处\",\"responsiblePerson\":\"张明\",\"functions\":[\"课程安排\",\"教学管理\",\"教师培训\"]},{\"departmentId\":\"DEP-002\",\"departmentName\":\"学生处\",\"responsiblePerson\":\"李娜\",\"functions\":[\"学生管理\",\"德育教育\",\"社团活动组织\"]}],\"grades\":[{\"gradeId\":\"G-01\",\"gradeName\":\"一年级\",\"classCount\":6,\"studentCount\":240},{\"gradeId\":\"G-09\",\"gradeName\":\"九年级\",\"classCount\":5,\"studentCount\":210}],\"facilities\":[\"多媒体教室\",\"实验室（物理、化学、生物）\",\"图书馆（藏书 5 万册）\",\"体育馆\",\"塑胶操场\",\"计算机教室\"],\"achievements\":{\"recentAwards\":[\"2024 年市教育系统先进单位\",\"2023 年科技创新大赛团体一等奖\"],\"furtherStudyRate\":{\"highSchool\":98.5,\"keyHighSchool\":65.2}}}";

        JSONObject jsonObject = JSONObject.parseObject(schools);

        String schoolName =jsonObject.getJSONObject("schoolInfo").getString("schoolName");


        System.out.println(schoolName);


        String schools2="[{\"schoolInfo\":{\"schoolId\":\"SCH-2025-001\",\"schoolName\":\"阳光实验学校\",\"establishYear\":1995,\"address\":{\"province\":\"江苏省\",\"city\":\"南京市\",\"district\":\"鼓楼区\",\"detail\":\"中山北路 123 号\"},\"contact\":{\"phone\":\"025-87654321\",\"email\":\"yangguang@school.edu.cn\",\"website\":\"http://www.yangguangschool.com\"},\"type\":\"九年一贯制\",\"studentCount\":2850,\"teacherCount\":198,\"feature\":[\"科技创新教育\",\"艺术特色\",\"体育传统项目学校\"]},\"departments\":[{\"departmentId\":\"DEP-001\",\"departmentName\":\"教务处\",\"responsiblePerson\":\"张明\",\"functions\":[\"课程安排\",\"教学管理\",\"教师培训\"]},{\"departmentId\":\"DEP-002\",\"departmentName\":\"学生处\",\"responsiblePerson\":\"李娜\",\"functions\":[\"学生管理\",\"德育教育\",\"社团活动组织\"]}],\"grades\":[{\"gradeId\":\"G-01\",\"gradeName\":\"一年级\",\"classCount\":6,\"studentCount\":240},{\"gradeId\":\"G-09\",\"gradeName\":\"九年级\",\"classCount\":5,\"studentCount\":210}],\"facilities\":[\"多媒体教室\",\"实验室（物理、化学、生物）\",\"图书馆（藏书 5 万册）\",\"体育馆\",\"塑胶操场\",\"计算机教室\"],\"achievements\":{\"recentAwards\":[\"2024 年市教育系统先进单位\",\"2023 年科技创新大赛团体一等奖\"],\"furtherStudyRate\":{\"highSchool\":98.5,\"keyHighSchool\":65.2}}}]";

        JSONObject jsonObject2 = JSONObject.parseArray(schools2).getJSONObject(0);

        String schoolName2 =jsonObject2.getJSONObject("schoolInfo").getString("schoolName");


        System.out.println(schoolName2);
    }
}

